﻿var empcode = $.getUrlParam('UserID')
window.onload = function() {
	$("#pwd-input").focus()
	$(".pwd-box").click(function() {
		$("#pwd-input").focus()
	})
	$("#btn").click(submit_newport)
	var $input1 = $(".fake-box1 input");
	$("#pwd-input1").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input1.eq("" + i + "").val(pwd[i]);
		}
		$input1.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {
			//执行其他操作  
		}
	});
	var $input2 = $(".fake-box2 input");
	$("#pwd-input2").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input2.eq("" + i + "").val(pwd[i]);
		}
		$input2.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {
			//执行其他操作  
		}
	});
}

function submit_newport() {
	var newpassport = $("#pwd-input1").val()
	newpassport = md5(newpassport)
	var soapdata
	soapdata = '<?xml version="1.0" encoding="utf-8"?>'
	soapdata += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
	soapdata += '<soap:Body>'
	soapdata += '<ResetPass xmlns="http://tempuri.org/">'
	soapdata += '<empcode>'+empcode+'</empcode>'
	soapdata += '<password>'+newpassport+'</password>'
	soapdata += '</ResetPass>'
	soapdata += '</soap:Body>'
	soapdata += '</soap:Envelope>'
	var datav = {
				data:soapdata,
				"SOAPAction": "http://tempuri.org/ResetPass"
		}
	$.ajax({
		"url": "http://drpapi.kukahome.com:8099/Lookfor/trans",
		"type": 'POST',
		"async": false,
		"dataType": 'text',
		"data": datav,
		"success": function(data) {
			var msg = $(data).find("ResetPassResult").text()
			msg = JSON.parse(msg)
			if(msg.error != 0) {
				$("#hint").html(msg.msg)
				$("#pwd-input1").val("")
				$(".fake-box1 input").val("")
				$("#pwd-input2").val("")
				$(".fake-box2 input").val("")
			} else {
				$("#hint").html(msg.msg+" 3s后跳转")
				setTimeout(function(){
					$("#pwd-input1").val("")
					$(".fake-box1 input").val("")
					$("#pwd-input2").val("")
					$(".fake-box2 input").val("")
					window.location.href="index.html?UserID="+empcode
				},3000)
			}
		},
		"error": function(data) {
			$("#pwd-input1").val("")
			$(".fake-box1 input").val("")
			$("#pwd-input2").val("")
			$(".fake-box2 input").val("")
			$("#hint").html("网络出问题了")
		},
		headers: {
			"Content-Type": 'application/x-www-form-urlencoded',
//			Accept: "XML",
//			"Content-Type": 'text/xml;charset=UTF-8',
//			"SOAPAction": "http://tempuri.org/ResetPass",
		}
	});
}